package com.cloudptt.api.product.func.call;


import com.cloudptt.api.pjsua2.MyCall;
import com.cloudptt.api.product.func.call.single.SingleCallInfo;
import com.cloudptt.api.product.log.Log;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.db.model.AddrInfo;



public class CallAttr 
{
	public static String THIS_FILE = "CallAttr";
	public static final int DefaultCallId                         = 0;
	public static final int CallDir_MO 		= 0;  //主叫        	
	public static final int CallDir_MT 		= 1;  //被叫 

	public static final int McType_PTT = 1;
	public static final int McType_VIDEO = 2;
	public static final int McType_DATA = 3;

	public static final int ShowViewType_Activity = 1;
	public static final int ShowViewType_FloatWindow = 2;

	public static final int CallType_Group = 1;
	public static final int CallType_Single = 2;

	public static final int CallType_Single_half = 11;
	public static final int CallType_Video_Push = 12;
	public static final int CallType_Video_Pull = 13;
	
	public static final int CallType_Video_Trans = 14;
	public static final int CallType_Video_TransGrp = 15;
	public static final int CallType_Video_PushGrp = 16;


	//    public static final int CallType_Webrtc_Single_voice = 12;
	//    public static final int CallType_Webrtc_Single = 13;
	//	public static final int CallType_Webrtc_PullFromUser = 14;//点对点视频上拉
	//	public static final int CallType_Webrtc_PushToUser = 15;//点对点视频下推
	////	public static final int CallType_Webrtc_PullFromServer = 16;//终端从服务器上拉视频 主叫
	////	public static final int CallType_Webrtc_PushToServer = 17;//终端到服务器视频下推 主叫
	////	public static final int CallType_Webrtc_PushToGroup = 18;//终端到群组视频下推 主叫
	//	public static final int CallType_Webrtc_OneKeyUpload = 19;//一键回传



	private String callIdStr = MyCall.DEF_CALL_ID_STR;
	private AddrInfo groupInfo = null;


	private AddrInfo called = null;
	private int callDir;
	//	private boolean isBroadcastGroup = false; 


	protected int callType = CallType_Single;
	protected boolean hasVideo = false;




	public CallAttr(int callType,AddrInfo called,int callDir,boolean useVideo)
	{
		this.callIdStr = MyCall.DEF_CALL_ID_STR;
		this.callType = callType;
		this.called = called;
		this.callDir = callDir;
		this.hasVideo = useVideo;
	}

	public CallAttr(AddrInfo groupInfo,AddrInfo called,int callDir,boolean isGroup)
	{
		Log.d(THIS_FILE, "CallAttr isGroup = " + isGroup);
		this.callIdStr = MyCall.DEF_CALL_ID_STR;
		//		this.mcType = McType_PTT;
		this.groupInfo = groupInfo;
		this.called = called;
		if(!isGroup)
		{
			this.callType = CallType_Single_half;
		}
		else
		{
			this.callType = CallType_Group;
		}
		this.callDir = callDir;
		this.hasVideo = false;
	}

	public String getCallKey()
	{
		if(callType == CallType_Group
				|| callType == CallType_Single_half)
		{
			return groupInfo.getMcId();
		}
		else 
		{
			return called.getMcId();
		}
	}

	public void updateCallIdStr(String callIdStr)
	{
		this.callIdStr = callIdStr;
	}
	public String getCallIdStr() {
		return callIdStr;
	}

	public int getCallType() {
		return callType;
	}

	public int getCallDir() {
		return callDir;
	}

	public AddrInfo getCalled() {
		return called;
	}

	public AddrInfo getCallLogAddrInfo(McIdInfo mcId)
	{
		if(CallDir_MT == callDir)
		{
			return called;
		}
		else
		{
			return mcId.toAddrInfo();
		}
	}

	public AddrInfo getGroupInfo() {
		return groupInfo;
	}

	public SingleCallInfo toPCallInfo(boolean isDac,int callState,boolean micEnabled)
	{
		String callKey = getCallKey();
		return new SingleCallInfo(callKey,callIdStr,callType,callDir,isDac,callState,micEnabled, hasVideo);
	}

	public boolean isHasVideo() {
		return hasVideo;
	}
	
	public boolean isSendNegotiate()
	{
		if(CallDir_MO == callDir
				&& CallAttr.CallType_Video_Pull == callType)
		{
			
			return true;
		}
		else if(CallDir_MT == callDir
				&& (CallAttr.CallType_Video_Push == callType
				|| CallAttr.CallType_Video_PushGrp == callType
				
				|| CallAttr.CallType_Video_Trans == callType
				|| CallAttr.CallType_Video_TransGrp == callType))
		{
			
			return true;
		}
		return false;
	}

	public String toString() 
	{
		StringBuffer strBuff = new StringBuffer("CallAttr:");
		strBuff.append("callKey = ").append(getCallKey()).append(",");
		//		strBuff.append("mcType = ").append(mcType).append(",");
		strBuff.append("callIdStr = ").append(callIdStr).append(",");
		strBuff.append("callType = ").append(callType).append(",");
		strBuff.append("callDir = ").append(callDir).append(",");
		strBuff.append("called = ").append(called).append(",");
		strBuff.append("hasVideo = ").append(hasVideo).append(",");
		strBuff.append("groupInfo = ").append(groupInfo).append(".");

		return strBuff.toString();
	}
}

